package com.xnx3.banmahuishou.userApplet.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xnx3.DateUtil;
import com.xnx3.banmahuishou.core.entity.Feedback;
import com.xnx3.j2ee.controller.BaseController;
import com.xnx3.j2ee.service.SqlService;
import com.xnx3.j2ee.util.ActionLogUtil;
import com.xnx3.j2ee.util.SafetyUtil;
import com.xnx3.j2ee.vo.BaseVO;

/**
 * 意见反馈相关
 * @author 王晓龙
 */
@Controller(value="BanmahuishouUserAppletFeedbackController")
@RequestMapping("/userApplet/feedback/")
public class FeedbackController extends BaseController {
	@Resource
	private SqlService sqlService;
	
	/**
	 * 提交意见反馈
	 * @param message 意见反馈信息
	 * @author 王晓龙
	 */
	@ResponseBody
	@RequestMapping(value="saveFeedBack.json",method = {RequestMethod.POST})
	public BaseVO saveFeedBack(HttpServletRequest request,
			@RequestParam(value = "message", required = true, defaultValue = "") String message){
	    if(getUserId() == 0) {
	    	return error("尚未登录");
	    }
	    if(!StringUtils.hasLength(message)) {
	    	return error("请输入您的意见");
	    }
	    if(message.length() > 255) {
	    	return error("您输入的反馈信息过多");
	    }
	    Feedback feedback = new Feedback();
	    feedback.setUserid(getUserId());
	    feedback.setAddTime(DateUtil.timeForUnix10());
	    feedback.setMessage(SafetyUtil.xssFilter(message));
	    sqlService.save(feedback);
	    
	    ActionLogUtil.insertUpdateDatabase(request, feedback.getId(), "保存意见反馈", feedback.toString());
	    return success();
	}
}
